package edu.lingnan.lingnanblog.controller.admin;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import edu.lingnan.lingnanblog.entity.Blogger;
import edu.lingnan.lingnanblog.service.BloggerClientService;
import edu.lingnan.lingnanblog.utils.ResponseUtil;
//import org.springframework.boot.configurationprocessor.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import net.sf.json.JSONObject;
import edu.lingnan.lingnanblog.service.BloggerClientService;
import edu.lingnan.lingnanblog.utils.DateUtil;
import edu.lingnan.lingnanblog.utils.ResponseUtil;


import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/consumer/admin/blogger")
public class BloggerAdminConsumerController {

    @Autowired
    private BloggerClientService bloggerClientService;

    @RequestMapping("/find")
    public String find(HttpServletResponse response, int id)throws Exception{
        Blogger blogger=bloggerClientService.selectOne(id);
        JSONObject jsonObject=JSONObject.fromObject(blogger);
        ResponseUtil.write(response, jsonObject);
       return null;
    }


    @RequestMapping("/modifyPassword")
    public String modifyPassword(String newPassword, int id, HttpServletResponse response)throws Exception{
        Blogger blogger=new Blogger();
        blogger.setPassword(newPassword);
        blogger.setId(id);
        System.out.println(blogger.getPassword());
        System.out.println(blogger.getId());
        boolean resultTotal=bloggerClientService.save(blogger);
        JSONObject result=new JSONObject();
        if(resultTotal){
           result.put("success", true);
        }else{
           result.put("success", false);
        }
       ResponseUtil.write(response, result);
       return null;
    }

    @RequestMapping("/logout")
    public String  logout()throws Exception{
        return "login";
    }
    @RequestMapping("/indexout")
    public String  indexout()throws Exception{
        return "login";
    }
}

